/*
 * Copyright (c) Hunan University.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <iostream>
#include "nlcpp.h"

using namespace nlcpp;
using namespace std;

static double func(double x) {
    return x * x * x - x - 1;
}

double func_iter(double x) {
    return pow(x + 1, 1.0 / 3.0);
}

void test_nonlinear_equation_solver() {
    cout << "========Test Nonlinear Equation Solvers ...========" << endl;
    double bisection_result = NonlinearEquationSolver::bisection(func, 1.0, 2.0, 0.01, 100);
    cout << "Result by bisection " << bisection_result << endl;

    double fixed_point_result = NonlinearEquationSolver::fixed_point_iteration(func_iter, 1.5, 0.01);
    cout << "Result by fixed point iteration " << fixed_point_result << endl;

    double newton_result = NonlinearEquationSolver::newton_iteration(func, 1.5, 0.01);
    cout << "Result by newton iteration " << newton_result << endl;
    
    cout << endl;
}
